<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body >
		<input type="text" id="txt1"></input>
		<input  type="text" id="txt2"></input>
		<button onclick="init();">对比</button>
		<div style="display:flex;">
		<div id="up"></div>
		<div id="down"></div>
		</div>
	</body>
</html>
<script>
	function init(){
		let pre = document.getElementById("txt1").value;
		let now = document.getElementById("txt2").value;
		pre = getList(pre);
		now = getList(now);
		
		let newUp = getNewList(pre,now);
		let newDown=getNewList(now,pre);
		let upStr = "升上去的：\n";
		newUp.map(item=>{
			upStr+=item.name+" "+item.code+"\n";
		})
		document.getElementById("up").innerText=upStr;
		
		let downStr="降下去的：\n";
		newDown.map(item=>{
			downStr+=item.name+" "+item.code+"\n";
		})
		document.getElementById("down").innerText=downStr;
	
	}
	
	function getNewList(pre,now){
		let newUp = [];
		pre.map(item=>{
			let flag = false;
			now.map(item2=>{
				if(item.code==item2.code){
					flag = true;
				}
			});
			if(!flag){
				newUp.push(item);
			}
		});
		return  newUp;
		
	}
	
	function getList(val){
	let myList = [];
		val.split(" ").map(item => {
			if (item.length > 10) {
				let node = {};
		
				let code = item.split("\t")[2];
				if (code.substr(0, 1) == "6") {
					node.code = "sh" + code;
				} else {
					node.code = "sz" + code;
				}
				node.name=item.split("\t")[1]
				node.cost = parseFloat(item.split("\t")[3]);
				myList.push(node);
			}
		}); 
		return myList;
	}
	
</script>
